/*
 * @Descripttion: 
 * @Author: xp
 * @Date: 2022-09-05 20:33:30
 */
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import goodsRouter from './modules/goodsRouter'
export let constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/home',
  //   meta: { title: '首页', icon: 'dashboard', affix: true },
  //   children: [
  //     {
  //       path: 'home',
  //       component: () => import('@/views/home/Index'),
  //       name: 'home',
  //       meta: { title: '首页', affix: true }
  //     },
  //   ]
  // },
  // ...goodsRouter,
]

export const asyncRoutes = [
  /** when your routing map is too long, you can split it into small modules **/
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // base: process.env.VUE_APP_BASE_API, // require service support mode为history 要配置base
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
        return savedPosition
    } else {
        return { x: 0, y: 0 }
    }
  },
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
// export function resetRouter() {
//   const newRouter = createRouter()
//   router.matcher = newRouter.matcher // reset router
// }

// router.beforeEach((to, from, next) => {
//   console.log(to, 2222222);
//   next()
// }) 
export default router
